import base64

import requests
import json

def send_auto_test_request():
    """
    发送POST请求到/auto_test端点，正确地通过multipart/form-data上传文件
    """
    url = "http://8.152.3.5:5000/auto_test"  # 根据实际情况修改URL
    
    # 准备JSON数据（作为表单字段发送）
    data = {
        'brand': 'mi',
        'testname': 'test1',
        'case': 'test_case5',
        'rpk_name': '知识大百科',
        'entity': 'hn'
    }
    
    # 准备文件
    file_path = r"C:\Users\chai0\sns-project\Analyze-advertising-events\Determining_ad\test\test\historical_data\data_hn_20250826_161828.parquet"
    
    try:
        with open(file_path, 'rb') as f:
            # 正确地通过multipart/form-data发送文件和数据
            files = {'all_df': f}
            response = requests.post(url, data=data, files=files)
            
        print(f"Status Code: {response.status_code}")
        print(f"Response Headers: {response.headers}")
        print(f"Response Text: {response.text}")
        
        # 尝试解析JSON响应
        try:
            json_response = response.json()
            print(f"Response JSON: {json_response}")
        except json.JSONDecodeError:
            print("Response is not valid JSON")
            
    except FileNotFoundError:
        print(f"文件未找到: {file_path}")
    except Exception as e:
        print(f"请求发送失败: {e}")

if __name__ == "__main__":
    send_auto_test_request()
